package com.abe.mvp.view.fragment;

import android.os.Bundle;
import android.view.LayoutInflater;
import android.view.View;
import android.view.View.OnClickListener;
import android.view.ViewGroup;
import android.widget.Button;
import android.widget.EditText;

import com.abe.config.SettingParam;
import com.abe.mvp.model.bean.SettingBean;
import com.abe.mvp.view.activity.FragmentCallbackListener.SettingCallbackListener;
import com.abe.mvp.view.fragment.base.BaseSettingFragment;
import com.abe.threadmill.R;

public class SettingPassFragment extends BaseSettingFragment {

	@SuppressWarnings("unused")
	private SettingCallbackListener callback;

	private Button pass_button_save_pass;
	private EditText pass_edit_current_pass, pass_edit_new_pass;

	@Override
	public View onCreateView(LayoutInflater inflater, ViewGroup container,
			Bundle savedInstanceState) {
		callback = (SettingCallbackListener) getActivity();
		View view = this.onCreateView(inflater,
				R.layout.activity_set_fragment_pass, container,
				savedInstanceState);
		initView(view);
		return view;
	}

	public void initView(View view) {
		pass_button_save_pass = (Button) view
				.findViewById(R.id.pass_button_save_pass);
		pass_edit_current_pass = (EditText) view
				.findViewById(R.id.pass_edit_current_pass);
		pass_edit_new_pass = (EditText) view
				.findViewById(R.id.pass_edit_new_pass);
		pass_button_save_pass.setOnClickListener(new OnClickListener() {
			@Override
			public void onClick(View view) {
				saveChange();
			}
		});
	}

	@Override
	protected void saveChange() {
		String old_pass = pass_edit_current_pass.getText().toString().trim();
		String new_pass = pass_edit_new_pass.getText().toString().trim();
		if (old_pass.equals("")) {
			showToast(R.string.common_pass_empty);
			return;
		}
		if (new_pass.equals("")) {
			showToast(R.string.common_pass_empty);
			return;
		}
		SettingBean settingBean = SettingParam.getSettingBean();
		if (old_pass.equals(settingBean.getSetPassword())) {
			settingBean.setSetPassword(new_pass);
			SettingParam.updateSettingBean(settingBean);
		} else {
			showToast(R.string.common_pass_error);
		}
	}

}
